package com.atguigu.flink.chapter11;

import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2021/10/20 15:17
 */
public class Flink07_SQL_Kafka {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        
        StreamTableEnvironment tenv = StreamTableEnvironment.create(env);
        
        tenv.executeSql("create table sensor(id string, ts bigint, vc int" +
                            ")with(" +
                            "  'connector' = 'kafka',\n" +
                            "  'properties.bootstrap.servers' = 'hadoop162:9092',\n" +
                            "  'properties.group.id' = 'Flink07_SQL_Kafka',\n" +
                            "  'topic' = 's1',\n" +
                            "  'scan.startup.mode' = 'latest-offset',\n" +
                            "  'format' = 'csv' " +
                            ")");
        
        
    
    
        tenv.executeSql("create table ss(id string, vc int" +
                            ")with(" +
                            "  'connector' = 'kafka',\n" +
                            "  'properties.bootstrap.servers' = 'hadoop162:9092',\n" +
                            "  'topic' = 's2',\n" +
                            "  'format' = 'json',\n " +
                            "   'sink.partitioner' = 'round-robin' " +
                            ")");
    
        Table result = tenv.sqlQuery("select id, vc from sensor");
        result.executeInsert("ss");
        
    }
}
